import store from '../store/index.js'
import http from "../utility/request.js";

import qs from 'qs'


// const baseUrl = process.env.NODE_ENV === 'development' ? 'http://www.qsxz.demos.cn.vc/' : 'http://api.relaverse.cn/'
// const baseUrl = process.env.NODE_ENV === 'development' ? 'http://test.qsxz.relaverse.cn/' : 'http://api.relaverse.cn/'
// const baseUrl = process.env.NODE_ENV === 'development' ? 'http://api.relaverse.cn/' : 'http://api.relaverse.cn/'
const baseUrl = process.env.NODE_ENV === 'development' ? 'http://sleep.dev.relaverse.cn' : 'http://sleep.dev.relaverse.cn'

// 收集加速度
export const acceleration = (params) => http.post(`/sleep/collect/acceleration`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken,
		...params
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});

// 收集分贝
export const decibel = (params) => http.post(`/sleep/collect/decibel`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken,
		...params
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});

// 音乐列表
export const musiclist = (params) => http.post(`/sleep/music/musiclist`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken,
		...params
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});

// 音乐分类
export const musicCate = (params) => http.post(`/sleep/music/catelist`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken,
		...params
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});


// 设置睡眠目标
export const setTarget = (params) => http.post(`/sleep/target/settings`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken,
		...params
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});

// 获取睡眠目标
export const getTargetApi = (params) => http.get(`/sleep/target/info`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken,
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});

// 开始睡觉
export const startSleep = (params) => http.post(`/sleep/sleep/fallasleep`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken,
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});

// 结束睡觉
export const endSleep = (params) => http.post(`/sleep/sleep/wakeup`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken,
		...params
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});

// 睡眠配置
export const configApi = (params) => http.post(`/sleep/config/common`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken,
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});

// 打卡挑战
export const challenge = (params) => http.post(`/sleep/activity/challenge`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken,
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});

// 领取奖励
export const getAward = (params) => http.post(`/sleep/award/receive`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken,
		...params
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});

// 分享
export const getShare = (params) => http.post(`/sleep/activity/share`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});


// 结果分享
export const getResultShare = (params) => http.post(`/sleep/sleep/share`, {
	data: qs.stringify({
		acctoken: store.state.collectionToken,
		...params
	}),
	baseUrl,
	header: {
		'content-type': 'application/x-www-form-urlencoded' 
	}
});